package com.lbc.service.impl;

import com.lbc.bean.dto.ScrollerDTO;
import com.lbc.bean.dto.ScrollerModifyDTO;
import com.lbc.bean.entity.Scroller;
import com.lbc.bean.vo.ScrollerVO;
import com.lbc.common.utils.JwtUtils;
import com.lbc.dao.custom.CtScrollerMapper;
import com.lbc.service.ScrollerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author xyl
 * @date 2021-03-16 20:38
 */
@Service
public class ScrollerServiceImpl implements ScrollerService {
    @Autowired
    private CtScrollerMapper scrollerMapper;

    @Override
    public int add(ScrollerDTO scrollerDTO) {
        Scroller scroller = new Scroller();
        scroller.setCreateTime(new Date());
        scroller.setCreateBy(JwtUtils.getUserId());
        scroller.setPic(scrollerDTO.getPic());
        scroller.setState(1);  //默认使用
        return scrollerMapper.insert(scroller);
    }

    @Override
    public int modify(ScrollerModifyDTO scrollerDTO) {
        Scroller scroller = new Scroller();
        BeanUtils.copyProperties(scrollerDTO,scroller);
        scroller.setUpdateBy(JwtUtils.getUserId());
        scroller.setUpdateTime(new Date());
        return scrollerMapper.updateByPrimaryKeySelective(scroller);
    }

    @Override
    public List<ScrollerVO> list(Integer state) {
        return scrollerMapper.selectByState(state);
    }

    @Override
    public int remove(Integer scrollerId) {
        return scrollerMapper.deleteByPrimaryKey(scrollerId);
    }
}
